package com.eecs393.drymouth;

import com.eecs393.drymouth.ConditionSearch;
import com.eecs393.drymouth.R;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import android.graphics.Rect;
import android.test.ActivityInstrumentationTestCase2;

public class ConditionSearchLayoutTest extends ActivityInstrumentationTestCase2<ConditionSearch> 
{

	private Button submit;
	private View searchLayout;
	private EditText symptoms;
	private TextView promptSearch;
	
	public ConditionSearchLayoutTest() 
	{
		super("com.eecs393.drymouth.conditionsearch", ConditionSearch.class);
	}

	protected void setUp() throws Exception 
	{
		super.setUp();
		
		ConditionSearch mainActivity = getActivity();
		submit = (Button) mainActivity.findViewById(R.id.Button_submitsearch);
		symptoms = (EditText) mainActivity.findViewById(R.id.EditText_symptoms);
		promptSearch = (TextView) mainActivity.findViewById(R.id.TextView_entersymptoms);
		searchLayout = (View) mainActivity.findViewById(R.id.searchLayout);
	}
	
	// check to see if Submit Button is displayed within visible screen
	public void testSubmitButtonOnScreen()
	{
		int fullWidth = searchLayout.getWidth();
		int fullHeight = searchLayout.getHeight();
		
		int[] searchLayoutLocation = new int[2];
		searchLayout.getLocationOnScreen(searchLayoutLocation);
		
		int[] viewLocation = new int[2];
		submit.getLocationOnScreen(viewLocation);
		
		Rect outRect = new Rect();
		submit.getDrawingRect(outRect);
		
		assertTrue("Submit button off the right of the screen", fullWidth 
				+ searchLayoutLocation[0] > outRect.width() + viewLocation[0]);
		assertTrue("Submit button off the bottom of the screen", fullHeight
				+ searchLayoutLocation[1] > outRect.height() + viewLocation[1]);
	}
	
	public void testSymptomEditTextOnScreen()
	{
		int fullWidth = searchLayout.getWidth();
		int fullHeight = searchLayout.getHeight();
		
		int[] searchLayoutLocation = new int[2];
		searchLayout.getLocationOnScreen(searchLayoutLocation);
		
		int[] viewLocation = new int[2];
		symptoms.getLocationOnScreen(viewLocation);
		
		Rect outRect = new Rect();
		symptoms.getDrawingRect(outRect);
		
		assertTrue("Symptom text box off the right of the screen", fullWidth
				+ searchLayoutLocation[0] > outRect.width() + viewLocation[0]);
		assertTrue("Symptom text box off the bottom of the screen", fullHeight
				+ searchLayoutLocation[1] > outRect.height() + viewLocation[1]);
	}
	
	public void testSymptomTextViewOnScreen()
	{
		int fullWidth = searchLayout.getWidth();
		int fullHeight = searchLayout.getHeight();
		
		int[] searchLayoutLocation = new int[2];
		searchLayout.getLocationOnScreen(searchLayoutLocation);
		
		int[] viewLocation = new int[2];
		promptSearch.getLocationOnScreen(viewLocation);
		
		Rect outRect = new Rect();
		promptSearch.getDrawingRect(outRect);
		
		assertTrue("Enter symptom text prompt off the right of the screen", fullWidth
				+ searchLayoutLocation[0] > outRect.width() + viewLocation[0]);
		assertTrue("Enter symptom text prompt off the right of the screen", fullHeight
				+ searchLayoutLocation[1] > outRect.height() + viewLocation[1]);
	}

}
